package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.MedicineBean;
import com.project.dao.MedicineDao;
import com.project.service.MedicineService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 药剂
 */

@Service
@Transactional
public class MedicineServiceImpl extends ServiceImpl<MedicineDao,MedicineBean> implements MedicineService {
    /**
     * 分页显示所有药剂/器械信息
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public IPage<MedicineBean> findAllMedicine(int pageNo, int pageSize) {
        Page<MedicineBean> page = new Page<>(pageNo,pageSize);
        IPage<MedicineBean> iPage = this.page(page);
        return iPage;
    }

    /**
     * 添加药剂
     * @param medicineBean
     */
    @Override
    public void addMedicine(MedicineBean medicineBean) {
        this.save(medicineBean);

    }

    /**
     * 根据药剂名称、防治类型、类别模糊查询药剂/器械信息
     * @param meName
     * @param meType
     * @param meSort
     * @return
     */
    @Override
    public IPage<MedicineBean> findName(int pageNo, int pageSize,
                                        String meName, String meType,
                                        String meSort) {
        Page<MedicineBean> page = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (meName!=null && !meName.equals("")){
            wrapper.like("f_meName",meName);
        }
        if (meType!=null && !meType.equals("")){
            wrapper.like("f_meType",meType);
        }
        if (meSort!=null && !meSort.equals("")){
            wrapper.like("f_meSort",meSort);
        }
        IPage<MedicineBean> iPage = this.page(page,wrapper);
        return iPage;
    }
}
